package com.ghd.dataviz;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author ：ghd
 * @date ：Created in 2020-04-05 23:27
 * @description：
 * @modified By：
 * @version: $
 */
@SpringBootApplication
public class DatavizMqApplication implements CommandLineRunner {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    public static void main(String[] args) {

        SpringApplication.run(DatavizMqApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        final AtomicInteger atomicInteger = new AtomicInteger();
        new Thread(() -> {
            while (true) {
                SendResult sendResult = rocketMQTemplate.syncSend("demo2",
                        "Hello, World!" + atomicInteger.decrementAndGet());
                System.out.printf("syncSend1 to topic %s sendResult=%s %n", "demo2", sendResult);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
